package com.liuya.mq.support.listener;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.liuya.common.support.email.Email;
import com.liuya.common.EmailUtil;

/**
 * 发送邮件队列
 *
 * @author liuya
 * @date 2016/8/24
 */
public class SendEmailListener implements MessageListener {
    private final Logger logger = LogManager.getLogger();

    public void onMessage(Message message) {
        try {
            Email email = (Email) ((ObjectMessage) message).getObject();
            logger.info("将发送邮件至：" + email.getSendTo());
            EmailUtil.sendEmail(email);
        } catch (JMSException e) {
            logger.error(e);
        }
    }
}
